<!--
Toast
props:
type: 类型，[loading,success,error]，默认loading
show_time: 显示的时间
slot:
默认插槽，显示的内容

-->
<template>
  <transition name="fade">
    <div class="container" v-if="show">
      <i class="fa fa-spinner load" aria-hidden="true" v-if="type==='loading'"></i>
      <i class="fa fa-check-circle" aria-hidden="true" v-if="type==='success'"></i>
      <i class="fa fa-times-circle" aria-hidden="true" v-if="type==='error'"></i>
      <p><slot>加载中...</slot></p>
    </div>
  </transition>
</template>
<style lang="less" scoped>
@import url('./theme.less');
  .fade-enter-active,
  .fade-leave-active {
    transition: opacity .5s;
  }
  .fade-enter,
  .fade-leave-to {
    opacity: 0
  }

  @keyframes load {
    from {
      transform: rotate(0deg);
    }
    to {
      transform: rotate(360deg);
    }
  }

  .container {
    width: @toast-width;
    border-radius: 6px;
    line-height: 20px;
    font-size: 15px;
    color: white;
    padding: 15px 10px;
    text-align: center;
    background: rgba(0, 0, 0, 0.8);
    position: fixed;
    top: 50vh;
    z-index: 510;
    left: 50vw;
    word-wrap: all;
    word-wrap: break-word;
    transform: translateX(-50%) translateY(-50%);
    /* 偏移50% */
    .load {
      animation: load 1.5s;
      animation-iteration-count: infinite;
      animation-timing-function: linear;
    }
    i {
      font-size: 20px;
      font-size: 30px;
      margin-bottom: 10px;
    }
  }

</style>
<script>
  export default {
    props: {
      type: {
        default: 'loading'
      },
      show_time: {
        default: 1000
      },
    },
    data(){
        return{
            show: false
        }
    },
    mounted: function () {
      setTimeout(() => {
        t.show = true;
      }, 0);
      var t = this;
      setTimeout(() => {
        t.show = false;
      }, t.show_time);
    }
  }

</script>
